package javango.contrib.hibernate;

import javango.forms.fields.FieldFactory;

import com.google.inject.Inject;

public class ModelFactory {

	HibernateUtil hibernateUtil;
	FieldFactory fieldFactory;
	@Inject
	public ModelFactory(FieldFactory fieldFactory, HibernateUtil hibernateUtil) {
		super();
		this.hibernateUtil = hibernateUtil;
		this.fieldFactory = fieldFactory;
	}
	
	public <T> ModelDao<T> dao(Class<T> modelClass) {
		return new ModelDao<T>(hibernateUtil, modelClass);
	}

	public ModelForm forInstance(Object instance) {
		ModelForm form = new ModelForm(fieldFactory, hibernateUtil);
		form.setInitial(instance);
		return form;
	}
	
	public ModelForm forModel(Class modelClass) {
		ModelForm form = new ModelForm(fieldFactory, hibernateUtil);
		form.setModel(modelClass);
		return form;
	}

}
